/* 
 * File:   Simulation.cpp
 * Author: Patrick
 * 
 * Created on 04 July 2012, 6:06 PM
 */

#include "simulation.h"

Simulation::Simulation(const std::string fileName): runFile(fileName){
    
    arraysCollection = NULL; //all these unneeded until called for
    ent = NULL;
    hyd = NULL;
    ind = NULL;
    arraysCollection = new Arrays(); //instantiate arrays object immediately
    
}

Simulation::Simulation(const Simulation& orig){
    
    
    
}

Simulation::~Simulation(){
    
    //empty for now
    
}

void Simulation::setupArrays(){
    
    //distribute simulation parameters to Arrays class
    
    arraysCollection -> Lx = ceil((xlimB - xlimA)/h);
    arraysCollection -> Ly = ceil((ylimB - ylimA)/h);
    arraysCollection -> Lz = ceil((zlimB - zlimA)/h);
    arraysCollection -> h = h;
    arraysCollection -> dt = dt;
    arraysCollection -> tmax = dt*nt;
    arraysCollection -> nsteps = nt;
    arraysCollection -> xDimSize = xdim;
    arraysCollection -> yDimSize = ydim;
    arraysCollection -> zDimSize = zdim;
    
    arraysCollection -> inflateXarr(xlimA, xlimB);
    arraysCollection -> inflateYarr(ylimA, ylimB);
    arraysCollection -> inflateZarr(zlimA, zlimB);
    arraysCollection -> inflateTarr(0);
    
   //check which equation objects were instantiated
    if(ind != NULL){
        
        arraysCollection->inflateA();
        
    } 
    
    if(hyd != NULL){
        
        arraysCollection->inflateVel();
        
    } 
    
    if(ent != NULL){
        
    }
    
}

void Simulation::setupEntropy(){    
    
    
    
}

void Simulation::setupHydro(){
    
    

}

void Simulation::setupInduction(){

    

}

void Simulation::setupParams(Params p){
    
    p.checkParam(runFile, p.distList);
    
    std::cout << "Distributing simulation parameters..." << std::endl;
    
    //distribute simulations parameters
    for(unsigned int i = 0; i < p.distList.size(); i++){
        
        //check parameters and distribute
        if(p.distList[i].compare("xdim") == 0){
            
            xdim = atoi(p.distList[i+1].c_str());
            
            i++;
            
            continue;
            
        } else if(p.distList[i].compare("ydim") == 0){
            
            if(p.distList[i+1].compare("$") == 0){
             
                ydim = xdim;
                
            } else{
            
                ydim = atoi(p.distList[i+1].c_str());
                
                i++;
                
            }
            
            continue;
            
        } else if(p.distList[i].compare("zdim") == 0){
            
            if(p.distList[i+1].compare("$") == 0){
             
                zdim = xdim;
                
            } else{
            
                zdim = atoi(p.distList[i+1].c_str());
                
                i++;
                
            }
            
            continue;
            
        } else if(p.distList[i].compare("xlim") == 0){
            
            xlimA = strtod(p.distList[i+1].c_str(), NULL);
            xlimB = strtod(p.distList[i+2].c_str(), NULL);
            
            i = i+2;
            
            continue;
            
            
        } else if(p.distList[i].compare("ylim") == 0){
            
            if(p.distList[i+1].compare("$") == 0){
             
                ylimA = xlimA;
                ylimB = xlimB;
                
            } else{
            
                ylimA = strtod(p.distList[i+1].c_str(), NULL);
                ylimB = strtod(p.distList[i+2].c_str(), NULL);
                
                i = i+2;
                
            }
            
            continue;
            
        } else if(p.distList[i].compare("zlim") == 0){
            
            if(p.distList[i+1].compare("$") == 0){
             
                zlimA = xlimA;
                zlimB = xlimB;
                
            } else{
            
                zlimA = strtod(p.distList[i+1].c_str(), NULL);
                zlimB = strtod(p.distList[i+2].c_str(), NULL);
                
                i = i+2;
                
            }
            
            continue;
            
        } else if(p.distList[i].compare("h") == 0){
            
            h = strtod(p.distList[i+1].c_str(), NULL);
            
            i++;
            
            continue;
            
        } else if(p.distList[i].compare("dt") == 0){
            
            dt = strtod(p.distList[i+1].c_str(), NULL);
            
            i++;
            
            continue;
            
        } else if(p.distList[i].compare("nt") == 0){
            
            nt = atoi(p.distList[i+1].c_str());
            
            i++;
            
            continue;
            
        } else if(p.distList[i].compare("induction") == 0){
            
            ind = new Induction();
            
            continue;
            
        } else if(p.distList[i].compare("nu") == 0){
            
            //nt = atoi(p.distList[i+1].c_str());
            
            ind -> nu = strtod(p.distList[i+1].c_str(), NULL);
            
            i++;
            
            continue;
            
        } else if(p.distList[i].compare("initA") == 0){
            
            //nt = atoi(p.distList[i+1].c_str());
            
            ind -> initOption = p.distList[i+1];
            
            i++;
            
            continue;
            
        } else if(p.distList[i].compare("initAampl") == 0){
            
            //nt = atoi(p.distList[i+1].c_str());
            
            ind -> initAampl = strtod(p.distList[i+1].c_str(), NULL);
            
            i++;
            
            continue;
            
        } else if(p.distList[i].compare("navier-stokes") == 0){
            
            hyd = new Hydro();
            
            continue;
            
        } else if(p.distList[i].compare("continuity") == 0){
            
            //cont = new Induction;
            
            continue;
            
        } else if(p.distList[i].compare("entropy") == 0){
            
            ent = new Entropy();
            
            continue;
            
        } else{ //found $
            
            continue;
            
        }
        
    }

}

void Simulation::solveInd(){
    
    //call Induction class to solve eqn
    ind -> solveEqn(*arraysCollection);
    
}

void Simulation::solveNS(){
    
    //call Hydro class to solve eqn
    
    
}